var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,$ = layui.jquery,laydate = layui.laydate;


layui.use(['tableEdit',"excel"], function () {
    let tableEdit = layui.tableEdit;
    let layer = layui.layer,
        excel = layui.excel;

    lay('.starttime').each(function(){
        laydate.render({
            elem: this
        });
    });

    form.render();//表单刷新
    let initData = [];
    table.render({
        elem: '#parentTable'
        ,data:initData
        ,toolbar: '#parentTableToolbar'
        ,totalRow: true
        ,cols: [[
            {field:'numbers',width: 50,type:'numbers',title:'序号', totalRowText: '合计'},
            {field:'billNo', title:'出库单号',sort:true, align: 'center', width: 120},
            {field:'outStockDate', title:'出库日期',sort:true, align: 'center', width: 120},
            {field:'receiptCompanyName', title:'单位名称',sort:true, align: 'center', width: 120},
            {field:'contactPerson', title:'联系人',sort:true, align: 'center', width: 120},
            {field:'contactPersonPhone', title:'联系人电话',sort:true, align: 'center', width: 120},
            {field:'contactPersonAddress', title:'联系人地址',sort:true, align: 'center', width: 120},
            {field:'outStockPerson', title:'出库人',sort:true, align: 'center', width: 120},
            {field:'createDate', title:'创建时间',sort:true, align: 'center', width: 120},
            {field:'lotNo', width: 120, title: '批次号', sort: true, align: 'center'},
            {field:'productCode', width: 120, title: '产品编码', sort: true, align: 'center'},
            {field:'specificationCode', width: 120, title: '规格编码', sort: true, align: 'center'},
            {field:'productUnit', width: 120, title: '产品单位', sort: true, align: 'center'},
            {field:'warehouseName', width: 120, title: '仓库名称', sort: true, align: 'center'},
            {field:'outStockQuantity', width: 120, title: '出库数量', sort: true, align: 'center', totalRow: true},
            {field:'productCname', width: 120, title: '中文名称', sort: true, align: 'center'},
            {field:'productEname', width: 120, title: '英文名称', sort: true, align: 'center'},
            {field:'productCdesc', width: 120, title: '中文描述', sort: true, align: 'center'},
            {field:'productEdesc', width: 120, title: '英文描述', sort: true, align: 'center'},
            {field:'trayNumber', width: 120, title: '托盘入数', sort: true, align: 'center', totalRow: true},
            {field:'totalTray', width: 120, title: '总托盘', sort: true, align: 'center', totalRow: true}
        ]]
        ,id: 'maininformationtableid'
        ,height: $(document).height() - $('#parentTable').offset().top - 75,
        //开启分页
        page: true,
        limits: [300,600,900],
    });


//搜索提交
    form.on('submit(submitform)', function(data){
        table.reload('maininformationtableid', {
            page: {
                curr: 1
            },
            url:'otherOutStock/statistics/productInfo',
            where:  data.field
        }, 'data');
        return false;
    });


    form.on('submit(exportData)', function (queryReq) {
        let index = layer.load(2, {
            shade: [0.4, '#000'],
            content: '加载中...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '40px',
                    'width': '200px'
                });
            }
        });
        $.ajax({
            data: queryReq.field,
            url:"otherOutStock/export/productInfoExport",
            success: function(res) {
                if(res.status == 200){
                    //配置列宽
                    let colConf = excel.makeColConfig({
                        'A': 80,
                        'X': 80
                    }, 80);
                    excel.exportExcel({
                        sheet1: res.data.data
                    }, '其它出库产品统计.xlsx', 'xlsx', {
                        extend: {
                            '!cols': colConf
                        }
                    });
                }else {
                    layer.msg(res.msg, {icon: 5});
                }
                layer.close(index);
                return false;
            }
        });
        return false;
    });
});
